import java.util.logging.Level;
import java.util.logging.Logger;

import com.agentfactory.agentspeak.debugger.AgentSpeakStateManagerFactory;
import com.agentfactory.agentspeak.debugger.inspector.AgentSpeakInspectorFactory;
import com.agentfactory.agentspeak.interpreter.AgentSpeakArchitectureFactory;
import com.agentfactory.eis.EISService;
import com.agentfactory.platform.core.AgentCreationException;
import com.agentfactory.platform.core.DuplicateAgentNameException;
import com.agentfactory.platform.core.IAgent;
import com.agentfactory.platform.core.NoSuchArchitectureException;
import com.agentfactory.platform.core.NoSuchServiceException;
import com.agentfactory.platform.impl.DefaultAgentPlatform;
import com.agentfactory.platform.impl.PlatformServiceManager;
import com.agentfactory.platform.impl.RoundRobinTimeSliceFixedScheduler;
import com.agentfactory.service.ams.AgentManagementService;
import com.agentfactory.visualiser.Debugger;

/**
 * Same main class as Vacworld only applied to the Robot Interface
 * only thing really changed is the name. 
 * 
 * @author rem
 */
public class RoboTennis{
    public static void main(String[] args) {
        // Create a new agent platform with a basic name and domain
        DefaultAgentPlatform platform = new DefaultAgentPlatform();
        platform.setName("test");
        platform.setDomain("ucd.ie");

        // Install a scheduling algorithm for executing the agents
        platform.setScheduler(new RoundRobinTimeSliceFixedScheduler());

        // Install and register the AFAPL2 Architecture Factory:
        // This enables support for instantiating AFAPL2 agents (i.e. agents
        // whose source code is identified by a .agent extension)
        platform.getArchitectureService().registerArchitectureFactory(new AgentSpeakArchitectureFactory());

		PlatformServiceManager manager = ((PlatformServiceManager) platform.getPlatformServiceManager());
		try {
			manager.addService(EISService.class, "eis");
		} catch (NoSuchServiceException ex) {
			Logger.getLogger(VacWorld.class.getName()).log(Level.SEVERE, null, ex);
		}

        // Install and start the Agent Factory Debugger
        Debugger debugger = new Debugger(platform);
        debugger.registerInspectorFactory(new AgentSpeakInspectorFactory());
        debugger.registerStateManagerFactory(new AgentSpeakStateManagerFactory());
        debugger.start();
        
        // Get a reference to the Agent Management Service so that the default
        // agent community can be created...
        AgentManagementService ams = (AgentManagementService) platform.getPlatformServiceManager().getServiceByName(AgentManagementService.NAME);
        try {
            IAgent agent = ams.createAgent("manager", "com/agentfactory/eis/EnvironmentManager.aspeak");
            agent.initialise("environment(eis, \"robot-env.jar\")");
            agent.initialise("design(henry, \"Robot.aspeak\")");
        } catch (NoSuchArchitectureException ex) {
            Logger.getLogger(RoboTennis.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DuplicateAgentNameException ex) {
            Logger.getLogger(RoboTennis.class.getName()).log(Level.SEVERE, null, ex);
        } catch (AgentCreationException ex) {
	    Logger.getLogger(RoboTennis.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
